package com.lv.dhart.widget;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.LinearLayout;

/**
 * android输入法弹出调整布局与沉浸式状态栏冲突+fitSystemWindows()被弃用问题
 */
public class MyLinearLayout extends LinearLayout {

    public MyLinearLayout(Context context) {
        super(context);
    }

    public MyLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected boolean fitSystemWindows(Rect insets) {
        insets.top = 0;
        return super.fitSystemWindows(insets);
    }
//    @Override
//    public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
//        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
//            Insets b = null;
//            b = Insets.of(0, -insets.getSystemWindowInsets().top
//                    , 0, 0);
//            //使两个inset.top字段相消为0
//            Insets result = Insets.add(insets.getSystemWindowInsets(), b);
//            WindowInsets.Builder builder=new WindowInsets.Builder(insets).setSystemWindowInsets(result);
//            return super.dispatchApplyWindowInsets(builder.build());
//        }
//        return super.dispatchApplyWindowInsets(insets);
//    }
}